package com.zpark.controller;

import com.zpark.pojo.Person;
import com.zpark.service.IPersonService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @PackageName: com.zpark.controller
 * @ClassName: PersonController
 * @Description:
 * @author: RZS
 * @date: 2024/4/23  8:50
 */
@RestController
@RequestMapping("/person")
public class PersonController {

    @Autowired
    private IPersonService personService;

    // 根据ID查询数据
    @GetMapping("/get_id/{id}")
    public Person getById(@PathVariable Integer id) {
        return personService.getById(id);
    }

    // 查询所有数据
    @GetMapping("/get_all")
    public List<Person> getAll() {
        return personService.getAll();
    }

    // 带条件的查询
    @PostMapping("/get_by_person")
    public List<Person> getByPerson(@RequestBody Person person){
        return personService.getByPerson(person);
    }

    // 添加用户
    @PostMapping("/add")
    public String addPerson(@RequestBody Person person){
        personService.addPerson(person);
        return "添加用户成功";
    }

    // 删除数据，根据ID删除
    @DeleteMapping("/del_id/{id}")
    public String removeById(@PathVariable Integer id){
        personService.removeById(id);
        return "根据id删除用户成功";
    }

    // 根据其他条件删除表
    @DeleteMapping("/del_per")
    public String removePerson(@RequestBody Person person){
        personService.removePerson(person);
        return "删除用户成功";
    }

    // 修改数据
    @PostMapping("/update")
    public String changePerson(@RequestBody Person person){
        personService.changePerson(person);
        return "修改用户数据成功";
    }
}
